home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / spu.com / SPU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-02  |  5.0 KB  |  183 lines

  1. /* 
  2. **                        Source Print Utility
  3. **                       ---------------------- 
  4. **   
  5. **
  6. **   This is a simple program designed to print source files.
  7. **   It will print the file name, page number, and date of last
  8. **   modification at the top of each page.  Each line of code is
  9. **   printed (usually in compressed mode) with it's relative line
  10. **   number.
  11. **
  12. **   The program was written using Microsoft C v5.1. It should be
  13. **   fairly easy to port to other printers (just change the escape
  14. **   codes in SPU.H).  The code and executable are released to the
  15. **   public domain.  All I ask is that if you make modifications
  16. **   please change the version number and describe the changes
  17. **   below.  (Place your modification notes *ABOVE* the previous
  18. **   version's notes).  Also, I would appreciate it if you could
  19. **   upload your new version to CompuServe.  Thanks and enjoy...
  20. **
  21. **   
  22. **                                               J.C. Ratjen
  23. **   
  24. **   
  25. **   
  26. **      Date       Version     Comments
  27. **    --------     -------    -----------------------------------------
  28. **    06/02/89       1.1      Fixed bug where SPU went into an endless
  29. **                            loop if it couldn't open the input file.
  30. **
  31. **                            Added wrapping of long lines
  32. **
  33. **                                                   JCR
  34. **
  35. **    04/17/89       1.0      Initial version released to public domain
  36. **   
  37. **                                                   J.C. Ratjen
  38. **                                                   CIS [75006,2277]
  39. */
  40.  
  41.  
  42. #include <dos.h>
  43. #include <stdio.h>
  44. #include <sys\types.h>
  45. #include <sys\stat.h>
  46. #include "spu.h"
  47.  
  48. #define FATTR     _A_ARCH|_A_HIDDEN|_A_RDONLY|_A_SYSTEM
  49. #define MAXCHAR   512         /* Maximum number of chars per record  */
  50. #define OFF       0
  51. #define ON        1
  52. #define TABVAL    3           /* Tab stops every 3 characters        */
  53.                               /* (you may want to change this to 8   */
  54. #define VERSION   "1.1"
  55.  
  56. void detab(), heading(), blurb(), get_fdate(), prn_cmd(), usage();
  57.  
  58. void main(argc, argv)
  59. int argc;
  60. char *argv[];
  61. {
  62.    FILE *fpin;
  63.    int len, line, outline, pnum, status;
  64.    char inrec[MAXCHAR+1], date[16];
  65.    struct find_t finfo;
  66.  
  67.    blurb();
  68.    if (argc<2) {
  69.       usage();
  70.       exit(0);
  71.    }
  72.    fflush(stdprn);
  73.    prn_cmd(RESET);
  74.    prn_cmd(SETUP);
  75.    while (--argc) {
  76.       status = _dos_findfirst(*++argv, FATTR, &finfo);
  77.       while (!status) {
  78.          if ((fpin=fopen(finfo.name,"r")) != NULL) {
  79.             line = outline = pnum = 0;
  80.             get_fdate(finfo.name, date);
  81.             strupr(*argv);
  82.             while (fgets(inrec,MAXCHAR,fpin)!=NULL) {
  83.                line++;
  84.                len = strlen(inrec);
  85.                if (outline%LPP==0 || !pnum)
  86.                   heading(finfo.name,++pnum,date);
  87.                detab(inrec);
  88.                fprintf(stdprn, "%4d%c  %.*s\r",line,SEPCHAR,TMW-7, inrec);
  89.                outline++;
  90.                if (len==(TMW-7))
  91.                   fprintf(stdprn,"\n");
  92.                while (len>(TMW-7)) {
  93.                   memmove(inrec,&inrec[TMW-7],len-(TMW-6));
  94.                   len = strlen(inrec);
  95.                   fprintf(stdprn, "\n    %c  %.*s\r",SEPCHAR,TMW-7, inrec);
  96.                   outline++;
  97.                }
  98.                printf("%s  line %d...\r",finfo.name,line);
  99.             }
  100.             fprintf(stdprn,"\f");
  101.             printf("%s done, %d page%s printed.\n",finfo.name,pnum,pnum>1 ? "s" : "");
  102.             fclose(fpin);
  103.          }
  104.          else 
  105.             printf("%s - unable to open.\n",finfo.name);
  106.          
  107.          status = _dos_findnext(&finfo);
  108.       }
  109.    }
  110.    prn_cmd(RESET);
  111. }
  112.  
  113. void blurb()
  114. {
  115.    printf("Source Print Utility - version %s (%s)\n",VERSION, __DATE__);
  116.    printf("<<< configured for %s >>>\n\n",PNAME);
  117. }
  118.  
  119. void detab(str)
  120. char *str;
  121. {
  122.    char *tmpstr;
  123.     int cnt;
  124.  
  125.    cnt = 0;
  126.    tmpstr = (char *)strdup(str);
  127.     while (*tmpstr) {
  128.         if (*tmpstr != '\t') 
  129.             str[cnt++] = *tmpstr++;
  130.         else {
  131.             str[cnt++] = ' ';
  132.             while (cnt%TABVAL) 
  133.                 str[cnt++] = ' ';
  134.          tmpstr++;
  135.         }
  136.     }
  137.     str[cnt] = '\0';
  138.    free((char *)tmpstr);
  139. }
  140.  
  141. void get_fdate(fname, dstr)
  142. char *fname,
  143.      *dstr;
  144. {
  145.    struct stat fdate;
  146.    char tmpstr[26];
  147.  
  148.    if (!stat(fname, &fdate)) {
  149.       strcpy(tmpstr,ctime(&fdate.st_atime));
  150.       sprintf(dstr,"%.2s-%.3s-%.2s %.5s",&tmpstr[8],&tmpstr[4],&tmpstr[22],&tmpstr[11]);
  151.    }
  152.    else 
  153.       *dstr = '\0';
  154. }
  155.  
  156. void heading(fname,page,dstr)
  157. char *fname;
  158. int page;
  159. char *dstr;
  160. {
  161.    int tmpint;
  162.  
  163.    if (page>1)
  164.       fprintf(stdprn,"\f");
  165.    tmpint = (HMW-10)/2;
  166.    prn_cmd(HDRFONT);
  167.    prn_cmd(ULINE);
  168.    fprintf(stdprn," %-*sPage %-3d%*s \r\n\n",tmpint,fname,page,tmpint,dstr);
  169.    prn_cmd(NO_ULINE);
  170.    prn_cmd(TXTFONT);
  171. }
  172.  
  173. void prn_cmd(cmd)
  174. char *cmd;
  175. {
  176.    fputs(cmd,stdprn);
  177. }
  178.  
  179. void usage()
  180. {
  181.    puts("Usage:   SPU file1 <file2> <fileN>\n");
  182. }
  183.